package Classic150;

public class 跳跃游戏2 {
    /*
        贪心，注意minStep的更改时机
     */
    public int jump(int[] nums) {
        int max = 0;
        int newMax = 0;
        int minStep = 0;
        for (int i = 0; i <= max; i++) {
            if (max >= nums.length - 1) return minStep;
            newMax = Math.max(newMax, i + nums[i]);
            if (i == max) {
                max = newMax;
                minStep++;
            }
        }
        return minStep;
    }
}
